// pages/distributionCenter/distributionCenter.js
var app = getApp();
var api = require("../../api.js");
var config = require("../../config.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user:{},
    actions: config.extract,        //调用配置文件支付设置
    cancelText: '取消',
    balance:0,
    distribution: 2,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  // 获取数据
  getData() {
    var that = this;
    app.request({
      url: api.distribution.index,
      method: 'post',
      data: {},
      success: function (res) {
        console.log(res)
        console.log(res.data)
        if(res.code==1){
          that.setData({
            user: res.data,
            balance: res.data.user.commission
          })
        }else{
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  // 分销订单
  distributionorders(){
     wx.navigateTo({
       url: '../distributionOrders/distributionOrders',
    })
  },
  distributionwithdrawal(e){
    wx.navigateTo({
      url: '../distributionFunds/distributionFunds?payment=' + e.currentTarget.dataset.id + '&type=1',
    })
  },
  myteam(){
    wx.navigateTo({
      url: '../distributionTeam/distributionTeam',
    })
  },
  // 分销订单
  qrcode() {
    wx.navigateTo({
      url: '../distributionCode/distributionCode',
    })
  },
  // 开启选择器
  openActionsheet() {
    this.setData({
      'show': true
    });
  },
  // 关闭选择器
  closeActionSheet() {
    this.setData({
      'show': false
    });
  },
  // 根据选择进行调用事件
  clickAction({
    detail
  }) {
    var that = this
    that.setData({
      page: 1
    })
    const {
      index
    } = detail;
    this.setData({
      [`actions[${index}].loading`]: true,
      actionType: index
    });
    // 0提现到余额 1银行卡 2 支付宝 参数nickname：昵称  alipay：支付宝账号
    switch (index) {
      case 0: // 0 提现到银行卡
        wx.navigateTo({
          url: '/pages/driver/withdraw-money/index?type=1' + '&&yue=' + that.data.balance + "&&distribution=" + that.data.distribution,
        });
        break;
      case 1: // 1 提现到支付宝
        wx.navigateTo({
          url: '/pages/driver/withdraw-ali/index?type=2' + '&&yue=' + that.data.balance + "&&distribution=" + that.data.distribution,
        });
        break;
      case 2: // 1 提现到余额
        wx.navigateTo({
          url: '/pages/driver/withdraw-wechat/index?type=0' + '&&yue=' + that.data.balance + "&&distribution=" + that.data.distribution,
        });
        break;
    }
    setTimeout(() => {
      this.setData({
        [`show`]: false,
        [`actions[${index}].loading`]: false
      });
    }, 100);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})